/*
 * Milestone3.c
 *
 * Created: 1/14/2013 12:17:26 PM
 *  Author: duerk@msoe.edu <Kevin Duer>
 *			zimmermane@msoe.edu <Evan Zimmerman>
 *			woottons@msoe.edu <Scott Wootton>
 *			
 * Purpose: The driver for the channelmonitor and transmission
 */ 

#include <stdbool.h>		//for boolean
#include "channelmonitor.h" //defines functions
#include "transmission.h"			//header file for this class
#include<avr/io.h>					//i/o register definitions
#include <stdio.h>
#include<avr/interrupt.h>			//interrupt definitions
#include<stdint.h>					//for uint types
#include <stdlib.h>			//for rand
#include <util/delay.h>
#include "uart.h"

FILE uart_str = FDEV_SETUP_STREAM(uart_putc,uart_getc,_FDEV_SETUP_RW);

/* int main()
 * Purpose: THe main function of the program
 * Parameters: None
 * Returns: None
 */
int main(){
	char text[MAX_BUFFER_SIZE];
	initChannelMonitor();
	//SET BAUD RATE = 9600
	uart_init(103);
	initTx();
	DDRB = 0xFF;						//set port c as output
	
	stdout = stdin = &uart_str;
	
	_delay_ms(100);
	printf("Welcome\n");
	
	while(1){
		if(idle){					//check idle
			PORTB |= (1<<1);
			if(UCSRA & (1<<UDRE)){
				fgets(text,MAX_BUFFER_SIZE, stdin);
				printf("%s", text);
				addNetworkChar(text);
			}
		}
		else{							//otherwise not idle
			PORTB &= ~(1<<1);
		}
		if(busy){					//check busy
			PORTB |= (1<<2);
		}
		else{							//otherwise not busy	
			PORTB &= ~(1<<2);
		}
		if(collision){				//check collision
			PORTB |= (1<<3);
		}	
		else{							//otherwise no collision
			PORTB &= ~(1<<3);
		}
	}
	return 0;
}
